package com.jjz.id.common.filter;

import jakarta.servlet.*;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


import java.io.IOException;

/**
 * @author ZJL
 * @create 2025-05-27-16:35
 * 过滤器--往所有的响应头里添加X-CORP:nc 这个类的作用是在 HTTP 响应中统一添加一个标识性 Header，用于标记系统来源或做前端识别，属于一种轻量级的请求增强。
 */

public class CorpFilter implements Filter {
    private static final Logger log = LoggerFactory.getLogger(CorpFilter.class);
    public static String HEADER_CORP = "X-CORP";
    public static String HEADER_CORP_VALUE = "nc";
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest httpServletRequest = (HttpServletRequest)servletRequest;
        log.info("-----------login path-----------" + httpServletRequest.getServletPath());
        HttpServletResponse response = (HttpServletResponse)servletResponse;
        response.addHeader(HEADER_CORP, HEADER_CORP_VALUE);
        filterChain.doFilter(servletRequest, servletResponse);
    }
}
